package com.situ.water_BE.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.situ.water_BE.mapper.BeFlowMapper;
import com.situ.water_BE.mapper.BeHistoryMapper;
import com.situ.water_BE.pojo.BeFlow;
import com.situ.water_BE.pojo.BeHistory;
import com.situ.water_BE.service.BeHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Angel
 * @since 2020-12-01
 */
@Service
public class BeHistoryServiceImpl extends ServiceImpl<BeHistoryMapper, BeHistory> implements BeHistoryService {
    @Autowired
    private BeHistoryMapper dao;
    @Autowired
    private BeFlowMapper beFlowDao;

    @Override
    public int add(String orderNo,Integer sessionId) {
        BeHistory history=new BeHistory();
        history.setOrderNo(orderNo);
        history.setStepID(1);
        history.setDatee(new Date());
        history.setEmpID(sessionId);
        history.setIsBack(false);
        return dao.insert(history);
    }

    @Override
    public int updateStepIdAdd(String orderNo,Integer stepId, Integer sessionId,Integer pd) {
        BeHistory history=new BeHistory();
        history.setOrderNo(orderNo);
        history.setStepID(stepId);
        history.setDatee(new Date());
        history.setEmpID(sessionId);
        if (pd==0){
            history.setIsBack(false);
        }
        if (pd==1){
            history.setIsBack(true);
        }
        return dao.insert(history);
    }

    @Override
    public List<Map> queryAllBeHistory(String orderNo) {
        return dao.queryAllBeHistory(orderNo);
    }

    @Override
    public List<BeHistory> queryByBeHistory(QueryWrapper<BeHistory> wrapper) {
        return dao.selectList(wrapper);
    }
    @Override
    public BeFlow queryByBeFlow(int id){

        return beFlowDao.selectById(id);
    }
}
